import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
//提现
main() {
  runApp(MyApp());
}

bool IsJiedan = true;
bool Isanniu = true;
bool check = true;

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primaryColor: Color.fromRGBO(51, 51, 51, 1),
      ),
      home: Page(),
    );
  }
}

class Page extends StatefulWidget {
  @override
  _PageState createState() => _PageState();
}

class _PageState extends State<Page> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomPadding: false,
      backgroundColor: Color.fromRGBO(236, 236, 236, 1),
      appBar: AppBar(
          titleSpacing: 0.0,
          title: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              FlatButton(
                materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                child: Row(
                  children: [
                    Icon(
                      Icons.arrow_back_ios,
                      color: Colors.white,
                    ),
                    Text(
                      '返回',
                      style: TextStyle(color: Colors.white, fontSize: 16),
                    )
                  ],
                ),
                onPressed: () {
                  Navigator.pop(context);
                },
              ),
              Container(
                child: Row(
                  children: [
                    Text(
                      '提现',
                      style: TextStyle(fontSize: 16),
                    ),
                    SizedBox(
                      width: 30,
                    )
                  ],
                ),
              ),
              IconButton(icon: Icon(Icons.more_horiz), onPressed: () {})
            ],
          )),
      body: Subject(),
    );
  }
}

class Subject extends StatefulWidget {
  @override
  _SubjectState createState() => _SubjectState();
}

class _SubjectState extends State<Subject> {
  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        RichText(
          text: TextSpan(
              style: TextStyle(
                color: Colors.grey,
                fontSize: 13,
              ),
              children: <TextSpan>[
                TextSpan(text: "剩余可提取余额:"),
                TextSpan(
                    text: "￥60.00",
                    style: TextStyle(color: Colors.red, fontSize: 18)),
              ]),
        ),
        Container(
          height: 400,
          color: Colors.white,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                margin: EdgeInsets.only(top: 10, left: 15),
                child: Text("提现到"),
              ),
              Divider(
                color: Colors.grey,
              ),
              ListTile(
                leading: Icon(Icons.question_answer, color: Colors.green),
                title: Text("微信红包"),
                trailing: Icon(Icons.done, color: Colors.green),
              ),
              Divider(
                color: Colors.grey.withOpacity(0.4),
              ),
              Container(
                margin: EdgeInsets.only(top: 10, left: 15),
                child: Text("提现金额："),
              ),
              Expanded(
                child: Container(
                    margin: EdgeInsets.only(left: 30, right: 30, top: 10),
                    child:  CustomRadio(),
              )
              )],
          ),
        ),
        Center(
            child: Container(
              width: 250,
              child: FlatButton(
                color: Colors.grey,
                child: Text("提交申请"),
                onPressed: () {
                  showDialog(
                      context: context,
                      barrierDismissible: false,
                      builder: (cont) {
                        return MyDiaLog();
                      });
            },
          ),
        ))
      ],
    );
  }
}

class CustomRadio extends StatefulWidget {
  @override
  createState() {
    return CustomRadioState();
  }
}

class CustomRadioState extends State<CustomRadio> {
  List<RadioModel> sampleData = new List<RadioModel>();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    sampleData.add(new RadioModel(false, '10元'));
    sampleData.add(new RadioModel(false, '20元'));
    sampleData.add(new RadioModel(false, '50元'));
    sampleData.add(new RadioModel(false, '100元'));
    sampleData.add(new RadioModel(false, '150元'));
    sampleData.add(new RadioModel(false, '200元'));
  }

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3,
            crossAxisSpacing: 10,
        ),
        itemCount: sampleData.length,
        itemBuilder: (BuildContext context, int index) {
          return new InkWell(
            //highlightColor: Colors.red,
            splashColor: Colors.blueAccent,
            onTap: () {
              setState(() {
                sampleData.forEach((element) => element.isSelected = false);
                sampleData[index].isSelected = true;
              });
            },
            child: new RadioItem(sampleData[index]),
          );
        },
      );
  }
}

class RadioItem extends StatelessWidget {
  final RadioModel _item;
  RadioItem(this._item);
  @override
  Widget build(BuildContext context) {
    return new Container(
      margin: new EdgeInsets.all(15.0),
      child: new Row(
        mainAxisSize: MainAxisSize.max,
        children: <Widget>[
          new Container(
            height: 60.0,
            width: 60.0,
            child: new Center(
              child: new Text(_item.buttonText,
                  style: new TextStyle(
                      color:
                      _item.isSelected ? Colors.white : Colors.black,
                      //fontWeight: FontWeight.bold,
                      fontSize: 18.0)),
            ),
            decoration: new BoxDecoration(
              color: _item.isSelected
                  ? Colors.blueAccent
                  : Colors.transparent,
              border: new Border.all(
                  width: 1.0,
                  color: _item.isSelected
                      ? Colors.blueAccent
                      : Colors.grey),
              borderRadius: const BorderRadius.all(const Radius.circular(2.0)),
            ),
          ),
        ],
      ),
    );
  }
}

class RadioModel {
  bool isSelected;
  final String buttonText;

  RadioModel(this.isSelected, this.buttonText);
}

class MyDiaLog extends Dialog {
  @override
  Widget build(BuildContext context) {
    Widget jd() {
      if (IsJiedan) {
        Isanniu = true;
        return SimpleDialog(
          children: <Widget>[
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Text("成功提示"),
                Divider(
                  color: Colors.black,
                ),
                Container(
                  padding: EdgeInsets.all(20),
                  alignment: Alignment.center,
                  child: Text(
                    "提交成功，红包已下发，您可以前往公众号首页领取红包",
                    textAlign: TextAlign.center,
                    style: TextStyle(fontSize: 15),
                  ),
                ),
                Divider(
                  color: Colors.black,
                ),
              ],
            ),
            GestureDetector(
              onTap: (){
                Navigator.pop(context);
              },
              child: Container(
                alignment: Alignment.center,
                child: Text("我知道了"),
              ),
            ),
          ],
        );
      }
      else {
        Isanniu = false;
        return SimpleDialog(
          children: <Widget>[
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Text("失败提示"),
                Divider(
                  color: Colors.black,
                ),
                Container(
                  margin: EdgeInsets.all(20),
                  child: Text(
                    "提现失败，红包发送不成功，请联系工作人员处理",
                    textAlign: TextAlign.center,
                    style: TextStyle(fontSize: 15),
                  ),
                ),
                Center(
                  child: Text("0592-5888888",style: TextStyle(color: Colors.blue),),
                ),
                Divider(
                  color: Colors.black,
                ),
              ],
            ),
          GestureDetector(
            onTap: (){
              Navigator.pop(context);
              },
            child: Container(
              alignment: Alignment.center,
              child: Text("我知道了"),
            ),
          ),
          ],
        );
      }
    }
    return jd();
  }
}

